<?php
/**
 * Created by PhpStorm.
 * User: minicart
 * Date: 2018/10/26
 * Time: 10:46
 */
namespace app\admin\service;
use app\models\ClassManagementModel;

/**
 * Class EducationalService
 * @package app\admin\service
 */
class EducationalService
{
    /**
     * 班课列表
     * @return array
     */
    public function class_management()
    {
        try {
            $page = input('page', 1);
            $listRows = input('limit', 5);
            $name = input('name', '');
            $phone = input('phone', '');
            $student_grade = input('student_grade', '');
            $register_time = input('register_time', '');
            $channel = input('channel', '');
            $where = [];
            if ($name) $where['name'] = $name;
            if ($phone) $where['phone'] = $phone;
            if ($student_grade) $where['student_grade'] = $student_grade;
            if ($register_time) $where['register_time'] = $register_time;
            if ($channel) $where['channel'] = $channel;
            $order = 'id desc';
			$where = [];
			if(get_current_type() == 4 || get_current_type() == 5){
				$where['campus_id'] = get_current_campus_id();
			}elseif (get_current_type() == 2 || get_current_type() == 3){
				$where['campus_id'] = ['in',get_current_campus_id()];
			}
            $customers = ClassManagementModel::pageLists($where, $page, $listRows, $order);
            return $customers;
        } catch (\Exception $ex) {
            return ['code' => 1, 'msg' => $ex->getMessage()];
        }
    }

    /**
     * @param $type
     * @return array
     */
    public function classLogic($type)
    {
        try {
            $data = input('post.');
            if($type == 1){
                ClassManagementModel::create($data);
            }
            return ['code' => 0, 'msg' => '新建班课成功'];
        } catch (\Exception $ex) {
            return ['code' => 1, 'msg' => $ex->getMessage()];
        }
    }
}